﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EntityLayer;
namespace DataLayer.DAO
{
  public  class clsClienteDAO
    {
        private BDCALLCENTEREntities ContextoDeObjs = new BDCALLCENTEREntities();
        public bool Insertar(Cliente Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("Cliente", Obj);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
           
        }
        public bool Modificar(Cliente obj)
        {

            try
            {
                ContextoDeObjs.AttachTo("Cliente", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(Cliente obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("Cliente", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        public List<Cliente> listar()
        {
            List<Cliente> lista = new List<Cliente>();
            var q = from c in ContextoDeObjs.Cliente
                    select c;
            lista = q.ToList();
            return lista;
        }

        public List<Persona> ListarClientePersona()
        {
            List<Persona> lista = new List<Persona>();

            var q = from c in ContextoDeObjs.Cliente
                    from p in ContextoDeObjs.Persona
                    where p.CodigoPersona == c.CodigoPersona
                    select p;

            lista = q.ToList();
            return lista;
        }
    }
}
